home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997…eptember: Technology Seed / ATS Aug-Sept '97.toast / Navigation Services SDK / Examples / Sampler / Sampler ƒ / document.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-18  |  17.1 KB  |  674 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        document.c
  3.  
  4.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #pragma segment DocSeg
  9.  
  10. #ifndef __DRAG__
  11. #include <Drag.h>
  12. #endif
  13.  
  14. #ifndef __TOOLUTILS__
  15. #include <ToolUtils.h>
  16. #endif
  17.  
  18.  
  19. #ifndef Common_Defs
  20. #include "Common.h"
  21. #endif
  22.  
  23. #ifndef __MYSPRINTF__
  24. #include "Mysprintf.h"
  25. #endif
  26.  
  27. #ifndef __NAVIGATION__
  28. #include "Navigation.h"
  29. #endif
  30.  
  31. const             printID = -8192;    // string rsrc ID if print driver name
  32. const OSType    strType = 'STR ';    // string resource type
  33.  
  34. extern short         gDocumentCount;
  35. extern Document*    gDocumentList[kMaxDocumentCount];
  36. extern short         gQuitting;
  37. extern short        gCanUndoDrag;
  38. extern WindowPtr    gUndoFrontmost, gLastFrontmost;
  39. extern Boolean        gCanDrag;
  40.  
  41. extern pascal OSErr MyTrackingHandler(short message, WindowPtr theWindow, void* handlerRefCon, DragReference theDrag);
  42. extern pascal OSErr MyReceiveDropHandler(WindowPtr theWindow, unsigned long handlerRefCon, DragReference theDrag);
  43.  
  44. void PositionDocumentParts(Document* theDocument);
  45. void DoDrawGrowIcon(WindowPtr theWindow);
  46.  
  47. DragReceiveHandlerUPP     receiveHandler;
  48. DragTrackingHandlerUPP     trackingHandler;
  49. DragSendDataUPP         sendHandler;
  50.  
  51. pascal void myventProc(const     NavEventCallbackMessage callBackSelctor, 
  52.                                                 NavCBRecPtr callBackParms, 
  53.                                                 NavCallBackUserData callBackUD);
  54. NavAskSaveChangesResult OpenAskSaveChanges(unsigned char* docName, Boolean quitting);
  55.  
  56.  
  57. // **********************************************************************
  58. // *
  59. // *    AddText()
  60. // *
  61. // **********************************************************************
  62. void AddText(Document* theDocument, Ptr text, long len)
  63. {
  64.     if (theDocument->theTE != NULL)
  65.         {
  66.         TEInsert(text,len,theDocument->theTE);
  67.         theDocument->dirty = true;
  68.         TESelView(theDocument->theTE);
  69.         AdjustScrollBar((Document*)GetWRefCon(theDocument->theWindow));
  70.         }
  71. }
  72.  
  73.  
  74. // **********************************************************************
  75. // *
  76. // *    AdjustDocumentView()
  77. // *
  78. // **********************************************************************
  79. void AdjustDocumentView(Document* theDocument)
  80. {    
  81.     short    delta, docTop, docTopLimit;
  82.  
  83.     delta = (theDocument->vScrollPos - GetControlValue(theDocument->vScroll)) * ScrollResolution;
  84.  
  85.     if (delta && theDocument->theTE)
  86.         {
  87.         if (delta > 0)
  88.             {
  89.             docTop = (**(theDocument->theTE)).destRect.top;
  90.             docTopLimit = (**(theDocument->theTE)).viewRect.top + TopMargin;
  91.             if (docTop + delta > docTopLimit)
  92.                 delta = docTopLimit - docTop;
  93.             }
  94.         TEScroll(0,delta,theDocument->theTE);
  95.         theDocument->vScrollPos = GetControlValue(theDocument->vScroll);
  96.         }
  97. }
  98.  
  99.  
  100. // **********************************************************************
  101. // *
  102. // *    AdjustScrollBar()
  103. // *
  104. // **********************************************************************
  105. void AdjustScrollBar(Document* theDocument)
  106. {    
  107.     short        docTop, docBottom, viewTop, viewBottom;
  108.     short        offTop, offBottom;
  109.     RgnHandle    viewRgn;
  110.  
  111.     if (theDocument->theTE != NULL)
  112.         {
  113.         docTop = (**(theDocument->theTE)).destRect.top;
  114.         docBottom = docTop + TEGetHeight(32767,0,theDocument->theTE);
  115.         viewTop = (**(theDocument->theTE)).viewRect.top;
  116.         viewBottom = (**(theDocument->theTE)).viewRect.bottom;
  117.     
  118.         offTop = ((viewTop - (docTop - TopMargin)) + ScrollResolution - 1) / ScrollResolution;
  119.         offBottom = (((docBottom + BottomMargin) - viewBottom) + ScrollResolution - 1) / ScrollResolution;
  120.         if (offTop < 0)
  121.             offTop = 0;
  122.         if (offBottom < 0)
  123.             offBottom = 0;
  124.     
  125.         theDocument->vScrollPos = offTop;
  126.     
  127.         SetControlMaximum(theDocument->vScroll,offTop + offBottom);
  128.         SetControlValue(theDocument->vScroll,offTop);
  129.     
  130.         viewRgn = NewRgn();
  131.         RectRgn(viewRgn,&(**(theDocument->theTE)).viewRect);
  132.         SectRgn(viewRgn,theDocument->hiliteRgn,theDocument->hiliteRgn);
  133.         DisposeRgn(viewRgn);
  134.         }
  135. }
  136.  
  137.  
  138. // **********************************************************************
  139. // *
  140. // *    PositionDocumentParts()
  141. // *
  142. // **********************************************************************
  143. void PositionDocumentParts(Document* theDocument)
  144. {    
  145.     Rect globalBounds = theDocument->theWindow->portRect;
  146.     Rect theRect;
  147.  
  148.     // size the vertical scrollbar:
  149.     SizeControl(theDocument->vScroll,kScrollBarWidth,(globalBounds.bottom - globalBounds.top - kScrollBarPos)+4);
  150.     MoveControl(theDocument->vScroll,globalBounds.right+2 - kScrollBarPos,-1);
  151.  
  152.     // size the horizontal scrollbar:
  153.     SizeControl(theDocument->hScroll,(globalBounds.right - globalBounds.left - kScrollBarPos)+4,kScrollBarWidth);
  154.     MoveControl(theDocument->hScroll,-1,(globalBounds.bottom - globalBounds.top - kScrollBarPos)+2);
  155.  
  156.     theRect = globalBounds;
  157.     theRect.right  -= 15;
  158.     theRect.bottom -= 15;
  159.     (**(theDocument->theTE)).viewRect = theRect;
  160.     (**(theDocument->theTE)).destRect.right = theRect.right - RightMargin;
  161.     TECalText(theDocument->theTE);
  162. }
  163.  
  164.  
  165. void SizeDocWindow(Document* theDocument)
  166. {
  167.     short length = 0;
  168.     short width = 0;
  169.     if (theDocument->fPict != NULL)
  170.         {
  171.         if ((**((PicHandle)theDocument->fPict)).picFrame.right >= qd.screenBits.bounds.right)
  172.             width = qd.screenBits.bounds.right-40;
  173.         else
  174.             width = (**((PicHandle)theDocument->fPict)).picFrame.right;
  175.  
  176.         if ((**((PicHandle)theDocument->fPict)).picFrame.bottom >= qd.screenBits.bounds.bottom)
  177.             length = qd.screenBits.bounds.bottom-10-LMGetMBarHeight()-27;
  178.         else
  179.             length = (**((PicHandle)theDocument->fPict)).picFrame.bottom;
  180.         }
  181.     else
  182.         {
  183.         length = qd.screenBits.bounds.bottom-10-LMGetMBarHeight()-27;    
  184.         width = kWindowWidth;
  185.         }
  186.     SizeWindow(theDocument->theWindow,width,length,true);
  187. }
  188.  
  189.  
  190. // **********************************************************************
  191. // *
  192. // *    NewDocument()
  193. // *
  194. // **********************************************************************
  195. Document* NewDocument(Boolean newDocAsPICT)
  196. {    
  197.     OSErr            theErr = noErr;
  198.     Document*        theDocument;
  199.     WindowPtr        theWindow;
  200.     Rect            theRect = {0,0,16,16};
  201.     TextStyle        theStyle;
  202.     TEStyleHandle    theStyleHandle;
  203.     Point            thePoint;
  204.     Rect            theSize;
  205.     short            length = 0, width = 0;
  206.     Str255            windTitle;
  207.     short            offset;
  208.     Rect            bounds;
  209.  
  210.     if (gDocumentCount == kMaxDocumentCount)
  211.         return ((Document*)0L);
  212.         
  213.     theDocument = gDocumentList[gDocumentCount++] = (Document*)NewPtr(sizeof(Document));
  214.     
  215.     // create the window
  216.     offset = gDocumentCount-1;
  217.     theDocument->theWindow = theWindow = NewCWindow(0L,&theSize,(unsigned char*)"\p",false,zoomDocProc,(WindowPtr)-1L,true,0L);
  218.     MoveWindow(theDocument->theWindow,(10+(offset*20)),(27+(offset*20)+LMGetMBarHeight()),true);
  219.     
  220.     bounds = theWindow->portRect;
  221.  
  222.     // setup the window title
  223.     Mysprintf((StringPtr)windTitle,(StringPtr)"untitled %d",gDocumentCount);
  224.     MyC2PStr((char*)windTitle);
  225.     SetWTitle(theDocument->theWindow,windTitle);
  226.     
  227.     SetWRefCon(theWindow,(long)theDocument);
  228.  
  229.     SetPort(theWindow);
  230.     thePoint.v = bounds.top;
  231.     thePoint.h = bounds.left;
  232.  
  233.     LocalToGlobal(&thePoint);
  234.     if (thePoint.h < 10)
  235.         MoveWindow(theWindow,InitialH,InitialV,false);
  236.  
  237.     if (newDocAsPICT)
  238.         {
  239.         theDocument->theTE = NULL;
  240.         theDocument->fPict = NULL;
  241.         theDocument->fPictLength = 0;
  242.         theDocument->fHeader = NULL;
  243.         }
  244.     else
  245.         {
  246.         theDocument->fPict = NULL;
  247.  
  248.         SizeDocWindow(theDocument);
  249.  
  250.         theDocument->vScroll = NewControl(theWindow,&theRect,(ConstStr255Param)"\p",true,0,0,0,scrollBarProc,(long)theDocument);
  251.         theDocument->hScroll = NewControl(theWindow,&theRect,(ConstStr255Param)"\p",true,0,0,0,scrollBarProc,(long)theDocument);
  252.  
  253.         theDocument->theTE = TEStyleNew(&theRect,&theRect);
  254.         (**(theDocument->theTE)).destRect.top    = TopMargin;
  255.         (**(theDocument->theTE)).destRect.left   = LeftMargin;
  256.         (**(theDocument->theTE)).destRect.bottom = 32767;
  257.         
  258.         TEAutoView(true,theDocument->theTE);
  259.  
  260.         TEFeatureFlag(teFOutlineHilite,teBitSet,theDocument->theTE);
  261.  
  262.         theDocument->hiliteRgn = NewRgn();
  263.         theStyleHandle = TEGetStyleHandle(theDocument->theTE);
  264.         (**theStyleHandle).teRefCon = (long)theDocument;
  265.  
  266.         theStyle.tsFont = 21;
  267.         theStyle.tsSize = 12;
  268.         TESetStyle(doFont + doSize,&theStyle,false,theDocument->theTE);
  269.         
  270.         theDocument->vScrollPos = 0;
  271.         theDocument->undoDragText = 0L;
  272.         
  273.         PositionDocumentParts(theDocument);
  274.  
  275.         if (gCanDrag && theDocument->theTE != NULL)
  276.             {
  277.             receiveHandler = NewDragReceiveHandlerProc(&MyReceiveDropHandler);
  278.             trackingHandler = NewDragTrackingHandlerProc(&MyTrackingHandler);
  279.             
  280.             theErr = InstallReceiveHandler(receiveHandler,theWindow,(void*)theDocument);
  281.             theErr = InstallTrackingHandler(trackingHandler,theWindow,(void*)theDocument);
  282.             }
  283.         }
  284.     
  285.     theDocument->fRefNum = 0;
  286.     theDocument->dirty = false;
  287.     
  288.     return theDocument;
  289. }
  290.  
  291.  
  292. // **********************************************************************
  293. // *
  294. // *    OpenAskSaveChanges()
  295. // *
  296. // **********************************************************************
  297. NavAskSaveChangesResult OpenAskSaveChanges(unsigned char* docName, Boolean quitting)
  298. {
  299.     OSStatus                theStatusErr     = noErr;
  300.     OSErr                     theErr             = noErr;
  301.     NavAskSaveChangesResult    reply             = 0;
  302.     NavAskSaveChangesAction    action             = 0;
  303.     NavEventProcPtr            eventProc         = NULL;
  304.     Str255                    appName;
  305.     NavEventProcUPP            evenProcUPP = NewNavEventProc(myEventProc);
  306.     
  307.     if (quitting)
  308.         action = kNavSaveChangesQuittingApplication;
  309.     else
  310.         action = kNavSaveChangesClosingDocument;
  311.         
  312.     GetIndString((unsigned char*)&appName,FileStringsID,sApplicationName);
  313.     
  314.     theErr = NavAskSaveChanges(    appName,
  315.                                 docName,
  316.                                 action,
  317.                                 &reply,
  318.                                 evenProcUPP,
  319.                                 (NavCallBackUserData)&gDocumentList);
  320.     
  321.     DisposeRoutineDescriptor(evenProcUPP);
  322.  
  323.     return reply;
  324. }
  325.  
  326.  
  327. // **********************************************************************
  328. // *
  329. // *    CloseDocument()
  330. // *
  331. // **********************************************************************
  332. void CloseDocument(Document* theDocument, Boolean quitting)
  333. {    
  334.     OSErr    theErr = noErr;
  335.     short    index;
  336.     Str255    theName;
  337.  
  338.     index = 0;
  339.     while ((gDocumentList[index] != theDocument) && (index < kMaxDocumentCount))
  340.         index++;
  341.  
  342.     if (gDocumentList[index] == theDocument)
  343.         {
  344.         if (theDocument->dirty)
  345.             {
  346.             NavAskSaveChangesResult result = 0;
  347.  
  348.             GetWTitle(theDocument->theWindow,(unsigned char*)&theName);
  349.             result = OpenAskSaveChanges(theName,quitting);
  350.             switch (result)
  351.                 {
  352.                 case askSaveChangesSave:
  353.                     if (!DoSaveDocument(theDocument))
  354.                         {
  355.                         gQuitting = false;    // don't quit yet!
  356.                         //return;
  357.                         }
  358.                     break;
  359.                 case askSaveChangesCancel:
  360.                     gQuitting = false;    // don't quit yet!
  361.                     //return;
  362.                     break;
  363.                 }
  364.             if (result == askSaveChangesCancel)
  365.                 return;    // don't close the document
  366.             }
  367.  
  368.         if (theDocument->fRefNum)
  369.             FSClose(theDocument->fRefNum);
  370.  
  371.         if (gCanDrag && theDocument->theTE != NULL)
  372.             {
  373.             theErr = RemoveReceiveHandler(receiveHandler,theDocument->theWindow);
  374.             theErr = RemoveTrackingHandler(trackingHandler,theDocument->theWindow);
  375.             }
  376.         
  377.         if (theDocument->theTE != NULL)
  378.             {
  379.             DisposeRgn(theDocument->hiliteRgn);
  380.             TEDispose(theDocument->theTE);
  381.             
  382.             if (theDocument->undoDragText)
  383.                 {
  384.                 DisposeHandle(theDocument->undoDragText);
  385.                 theDocument->undoDragText = 0L;
  386.                 }
  387.             }
  388.         else
  389.             {
  390.             if (theDocument->fPict != NULL)
  391.                 KillPicture((PicHandle)theDocument->fPict);    
  392.             if (theDocument->fHeader != NULL)
  393.                 DisposeHandle(theDocument->fHeader);
  394.             }
  395.  
  396.         DisposeWindow(theDocument->theWindow);
  397.  
  398.         while (index < kMaxDocumentCount)
  399.             {
  400.             gDocumentList[index] = gDocumentList[index + 1];
  401.             index++;
  402.             }
  403.  
  404.         DisposePtr((Ptr)theDocument);
  405.         gDocumentCount--;
  406.     }
  407. }
  408.  
  409.  
  410. // **********************************************************************
  411. // *
  412. // *    DoActivateDocument()
  413. // *
  414. // **********************************************************************
  415. void DoActivateDocument(Document* theDocument, short activate)
  416. {    
  417.     if (theDocument->theTE != NULL)
  418.         {
  419.         if (activate)
  420.             {
  421.             TEActivate(theDocument->theTE);
  422.             HiliteControl(theDocument->vScroll,0);
  423.             HiliteControl(theDocument->hScroll,0);
  424.             DoDrawGrowIcon(theDocument->theWindow);
  425.             TEGetHiliteRgn(theDocument->hiliteRgn,theDocument->theTE);
  426.             }
  427.         else
  428.             {
  429.             TEDeactivate(theDocument->theTE);
  430.             HiliteControl(theDocument->vScroll,255);
  431.             HiliteControl(theDocument->hScroll,255);
  432.             DoDrawGrowIcon(theDocument->theWindow);
  433.             }
  434.         }
  435. }
  436.  
  437.  
  438. // **********************************************************************
  439. // *
  440. // *    IsDocumentWindow()
  441. // *
  442. // **********************************************************************
  443. Document* IsDocumentWindow(WindowPtr theWindow)
  444. {    
  445.     short        index = 0;
  446.     Document*    theDocument;
  447.  
  448.     theDocument = (Document*)GetWRefCon(theWindow);
  449.  
  450.     while ((gDocumentList[index] != theDocument) && (index < gDocumentCount))
  451.         index++;
  452.  
  453.     if (gDocumentList[index] == theDocument)
  454.         return(theDocument);
  455.     else
  456.         return((Document*)0L);
  457. }
  458.  
  459.  
  460. // **********************************************************************
  461. // *
  462. // *    DoSelectAllDocument()
  463. // *
  464. // **********************************************************************
  465. void DoSelectAllDocument(Document* theDocument)
  466. {
  467.     if (theDocument && (theDocument->theTE))
  468.         TESetSelect(0,32767,theDocument->theTE);
  469. }
  470.  
  471.  
  472. // **********************************************************************
  473. // *
  474. // *    DisableUndoDrag()
  475. // *
  476. // **********************************************************************
  477. void DisableUndoDrag()
  478. {    
  479.     short        index;
  480.     Document*    theDoc;
  481.  
  482.     gCanUndoDrag = slCantUndo;
  483.  
  484.     index = gDocumentCount;
  485.     while (index--)
  486.         {
  487.         theDoc = gDocumentList[index];
  488.         if (theDoc->undoDragText)
  489.             {
  490.             DisposeHandle(theDoc->undoDragText);
  491.             theDoc->undoDragText = 0L;
  492.             }
  493.         }
  494. }
  495.  
  496.  
  497. // **********************************************************************
  498. // *
  499. // *    DoUndoDrag()
  500. // *
  501. // **********************************************************************
  502. void DoUndoDrag()
  503. {    
  504.     short        index, selStart, selEnd;
  505.     Document*    theDoc;
  506.     Handle        theText;
  507.     WindowPtr    theWindow;
  508.     Rect        theRect;
  509.  
  510.     if (gCanUndoDrag != slCantUndo)
  511.         {
  512.         theWindow = 0L;
  513.         index = gDocumentCount;
  514.         while (index--)
  515.             {
  516.             theDoc = gDocumentList[index];
  517.  
  518.             SetPort(theDoc->theWindow);
  519.             
  520.             if (theText = theDoc->undoDragText)
  521.                 {
  522.                 Rect        bounds = theDoc->theWindow->portRect;
  523.  
  524.                 theDoc->undoDragText = (**theDoc->theTE).hText;
  525.                 (**theDoc->theTE).hText = theText;
  526.  
  527.                 TECalText(theDoc->theTE);
  528.  
  529.                 selStart = theDoc->undoSelStart;
  530.                 selEnd   = theDoc->undoSelEnd;
  531.                 TESetSelect(selStart,selEnd,theDoc->theTE);
  532.                 theDoc->undoSelStart = theDoc->lastSelStart;
  533.                 theDoc->undoSelEnd   = theDoc->lastSelEnd;
  534.                 theDoc->lastSelStart = selStart;
  535.                 theDoc->lastSelEnd   = selEnd;
  536.  
  537.                 theRect = bounds;
  538.                 theRect.right  -= 15;
  539.                 theRect.bottom -= 15;
  540.                 EraseRect(&theRect);
  541.                 TEUpdate(&theRect,theDoc->theTE);
  542.                 }
  543.             }
  544.  
  545.         if (gCanUndoDrag == slUndoDrag)
  546.             gCanUndoDrag = slRedoDrag;
  547.         else
  548.             gCanUndoDrag = slUndoDrag;
  549.  
  550.         theWindow = gUndoFrontmost;
  551.         gUndoFrontmost = gLastFrontmost;
  552.         gLastFrontmost = theWindow;
  553.         }
  554. }
  555.  
  556.  
  557. // *****************************************************************************
  558. // *
  559. // *    DoDrawGrowIcon()
  560. // *
  561. // *****************************************************************************
  562. void DoDrawGrowIcon(WindowPtr theWindow)
  563. {
  564.     RgnHandle saveClipRgn = NewRgn();
  565.     Rect tempRect;
  566.  
  567.     if (saveClipRgn)
  568.         {
  569.         GetClip(saveClipRgn);
  570.     
  571.         SetRect(&tempRect,
  572.                 theWindow->portRect.right-15,
  573.                 theWindow->portRect.bottom-15,
  574.                 theWindow->portRect.right,
  575.                 theWindow->portRect.bottom);
  576.         ClipRect(&tempRect);
  577.         DrawGrowIcon(theWindow);
  578.         
  579.         SetClip(saveClipRgn);
  580.         DisposeRgn(saveClipRgn);
  581.         }
  582.     else
  583.         DrawGrowIcon(theWindow);
  584. }
  585.  
  586.  
  587. // *****************************************************************************
  588. // *
  589. // *    UpdateWindow()
  590. // *
  591. // *    Update event is received for a document window.
  592. // *
  593. // *****************************************************************************
  594. void UpdateWindow(Document* theDocument)
  595. {    
  596.     WindowPtr     theWindow = theDocument->theWindow;
  597.     Rect        bounds = theDocument->theWindow->portRect;
  598.     
  599.     SetPort(theWindow);
  600.     
  601.     BeginUpdate(theWindow);
  602.  
  603.     EraseRect(&bounds);
  604.     if (theDocument->theTE != NULL)
  605.         {
  606.         DrawControls(theWindow);
  607.         DoDrawGrowIcon(theWindow);
  608.         if (theDocument->theTE)
  609.             TEUpdate(&bounds,theDocument->theTE);
  610.         }
  611.     else
  612.         {
  613.         if (theDocument->fPict != NULL)
  614.             DrawPicture((PicHandle)theDocument->fPict,&((**((PicHandle)theDocument->fPict)).picFrame));
  615.         }
  616.     EndUpdate(theWindow);
  617. }
  618.  
  619.  
  620. // *****************************************************************************
  621. // *
  622. // *    DoZoomDocument()
  623. // *
  624. // *****************************************************************************
  625. void DoZoomDocument(Document* theDocument, WindowPtr theWindow, short thePart)
  626. {
  627.     GrafPtr    oldPort;
  628.     GetPort(&oldPort);
  629.     
  630.     SetPort(theWindow);
  631.     EraseRect(&theWindow->portRect);
  632.     ZoomWindow(theWindow,thePart,theWindow == FrontWindow());
  633.     
  634.     if (theDocument->theTE != NULL)
  635.         {
  636.         PositionDocumentParts((Document*)GetWRefCon(theWindow));
  637.         AdjustScrollBar((Document*)GetWRefCon(theWindow));
  638.         DoDrawGrowIcon(theWindow);
  639.         }
  640.  
  641.     InvalRect(&theWindow->portRect);
  642.  
  643.     SetPort(oldPort);
  644. }
  645.  
  646.  
  647. // *****************************************************************************
  648. // *
  649. // *    GrowDocumentWindow()
  650. // *
  651. // *****************************************************************************
  652. void GrowDocumentWindow(WindowPtr theWindow, Point thePoint)
  653. {    
  654.     long    result;
  655.     Rect    sizeRect;
  656.     Rect    bounds = theWindow->portRect;
  657.  
  658.     SetPort(theWindow);
  659.     
  660.     sizeRect = qd.screenBits.bounds;
  661.     if (!(result = GrowWindow(theWindow,thePoint,&sizeRect)))
  662.         return;
  663.         
  664.     SizeWindow(theWindow,LoWord(result),HiWord(result),false);
  665.  
  666.     PositionDocumentParts((Document*)GetWRefCon(theWindow));
  667.  
  668.     AdjustScrollBar((Document*)GetWRefCon(theWindow));
  669.  
  670.     DoDrawGrowIcon(theWindow);
  671.  
  672.     bounds = theWindow->portRect;
  673.     InvalRect(&bounds);
  674. }